<!doctype html>
<html lang="en" data-color-mode="dark">
<head>
<meta charset="utf-8">
<title>Docker 备忘清单
 &#x26;  docker cheatsheet &#x26;  Quick Reference</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta description="这是 Docker 的快速参考备忘单。 你可以在这里找到最常见的 Docker 命令。

入门，为开发人员分享快速参考备忘单。">
<meta keywords="docker,reference,Quick,Reference,cheatsheet,cheat,sheet">
<link rel="icon" href="data:image/svg+xml,%3Csvg%20viewBox%3D%220%200%2024%2024%22%20fill%3D%22none%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20height%3D%221em%22%20width%3D%221em%22%3E%20%3Cpath%20d%3D%22m21.66%2010.44-.98%204.18c-.84%203.61-2.5%205.07-5.62%204.77-.5-.04-1.04-.13-1.62-.27l-1.68-.4c-4.17-.99-5.46-3.05-4.48-7.23l.98-4.19c.2-.85.44-1.59.74-2.2%201.17-2.42%203.16-3.07%206.5-2.28l1.67.39c4.19.98%205.47%203.05%204.49%207.23Z%22%20fill%3D%22%23c9d1d9%22%2F%3E%20%3Cpath%20d%3D%22M15.06%2019.39c-.62.42-1.4.77-2.35%201.08l-1.58.52c-3.97%201.28-6.06.21-7.35-3.76L2.5%2013.28c-1.28-3.97-.22-6.07%203.75-7.35l1.58-.52c.41-.13.8-.24%201.17-.31-.3.61-.54%201.35-.74%202.2l-.98%204.19c-.98%204.18.31%206.24%204.48%207.23l1.68.4c.58.14%201.12.23%201.62.27Zm2.43-8.88c-.06%200-.12-.01-.19-.02l-4.85-1.23a.75.75%200%200%201%20.37-1.45l4.85%201.23a.748.748%200%200%201-.18%201.47Z%22%20fill%3D%22%23228e6c%22%20%2F%3E%20%3Cpath%20d%3D%22M14.56%2013.89c-.06%200-.12-.01-.19-.02l-2.91-.74a.75.75%200%200%201%20.37-1.45l2.91.74c.4.1.64.51.54.91-.08.34-.38.56-.72.56Z%22%20fill%3D%22%23228e6c%22%20%2F%3E%20%3C%2Fsvg%3E" type="image/svg+xml">
<link rel="stylesheet" href="../style/style.css">
<link rel="stylesheet" href="../style/katex.css">
</head>
<body><nav class="header-nav"><div class="max-container"><a href="../index.html" class="logo"><svg viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg" height="1em" width="1em">
  <path d="m21.66 10.44-.98 4.18c-.84 3.61-2.5 5.07-5.62 4.77-.5-.04-1.04-.13-1.62-.27l-1.68-.4c-4.17-.99-5.46-3.05-4.48-7.23l.98-4.19c.2-.85.44-1.59.74-2.2 1.17-2.42 3.16-3.07 6.5-2.28l1.67.39c4.19.98 5.47 3.05 4.49 7.23Z" fill="#c9d1d9"></path>
  <path d="M15.06 19.39c-.62.42-1.4.77-2.35 1.08l-1.58.52c-3.97 1.28-6.06.21-7.35-3.76L2.5 13.28c-1.28-3.97-.22-6.07 3.75-7.35l1.58-.52c.41-.13.8-.24 1.17-.31-.3.61-.54 1.35-.74 2.2l-.98 4.19c-.98 4.18.31 6.24 4.48 7.23l1.68.4c.58.14 1.12.23 1.62.27Zm2.43-8.88c-.06 0-.12-.01-.19-.02l-4.85-1.23a.75.75 0 0 1 .37-1.45l4.85 1.23a.748.748 0 0 1-.18 1.47Z" fill="#228e6c"></path>
  <path d="M14.56 13.89c-.06 0-.12-.01-.19-.02l-2.91-.74a.75.75 0 0 1 .37-1.45l2.91.74c.4.1.64.51.54.91-.08.34-.38.56-.72.56Z" fill="#228e6c"></path>
</svg>
<span class="title">Quick Reference</span></a><div class="menu"><a href="javascript:void(0);" class="searchbtn" id="searchbtn"><svg xmlns="http://www.w3.org/2000/svg" height="1em" width="1em" viewBox="0 0 18 18">
  <path fill="currentColor" d="M17.71,16.29 L14.31,12.9 C15.4069846,11.5024547 16.0022094,9.77665502 16,8 C16,3.581722 12.418278,0 8,0 C3.581722,0 0,3.581722 0,8 C0,12.418278 3.581722,16 8,16 C9.77665502,16.0022094 11.5024547,15.4069846 12.9,14.31 L16.29,17.71 C16.4777666,17.8993127 16.7333625,18.0057983 17,18.0057983 C17.2666375,18.0057983 17.5222334,17.8993127 17.71,17.71 C17.8993127,17.5222334 18.0057983,17.2666375 18.0057983,17 C18.0057983,16.7333625 17.8993127,16.4777666 17.71,16.29 Z M2,8 C2,4.6862915 4.6862915,2 8,2 C11.3137085,2 14,4.6862915 14,8 C14,11.3137085 11.3137085,14 8,14 C4.6862915,14 2,11.3137085 2,8 Z"></path>
</svg><span>搜索</span><span>⌘K</span></a><a href="https://github.com/jaywcjlove/reference/blob/main/docs/docker.md" class="" target="__blank"><svg viewBox="0 0 36 36" fill="currentColor" height="1em" width="1em"><path d="m33 6.4-3.7-3.7a1.71 1.71 0 0 0-2.36 0L23.65 6H6a2 2 0 0 0-2 2v22a2 2 0 0 0 2 2h22a2 2 0 0 0 2-2V11.76l3-3a1.67 1.67 0 0 0 0-2.36ZM18.83 20.13l-4.19.93 1-4.15 9.55-9.57 3.23 3.23ZM29.5 9.43 26.27 6.2l1.85-1.85 3.23 3.23Z"></path><path fill="none" d="M0 0h36v36H0z"></path></svg><span>编辑</span></a><button id="darkMode" type="button"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor" class="light" height="1em" width="1em">
  <path d="M6.995 12c0 2.761 2.246 5.007 5.007 5.007s5.007-2.246 5.007-5.007-2.246-5.007-5.007-5.007S6.995 9.239 6.995 12zM11 19h2v3h-2zm0-17h2v3h-2zm-9 9h3v2H2zm17 0h3v2h-3zM5.637 19.778l-1.414-1.414 2.121-2.121 1.414 1.414zM16.242 6.344l2.122-2.122 1.414 1.414-2.122 2.122zM6.344 7.759 4.223 5.637l1.415-1.414 2.12 2.122zm13.434 10.605-1.414 1.414-2.122-2.122 1.414-1.414z"></path>
</svg>
<svg xmlns="http://www.w3.org/2000/svg" fill="currentColor" viewBox="0 0 24 24" class="dark" height="1em" width="1em">
  <path d="M12 11.807A9.002 9.002 0 0 1 10.049 2a9.942 9.942 0 0 0-5.12 2.735c-3.905 3.905-3.905 10.237 0 14.142 3.906 3.906 10.237 3.905 14.143 0a9.946 9.946 0 0 0 2.735-5.119A9.003 9.003 0 0 1 12 11.807z"></path>
</svg>
</button><script src="../js/dark.js?v=1.5.2"></script><a href="https://github.com/jaywcjlove/reference" class="" target="__blank"><svg viewBox="0 0 16 16" fill="currentColor" height="1em" width="1em"><path d="M8 0C3.58 0 0 3.58 0 8c0 3.54 2.29 6.53 5.47 7.59.4.07.55-.17.55-.38 0-.19-.01-.82-.01-1.49-2.01.37-2.53-.49-2.69-.94-.09-.23-.48-.94-.82-1.13-.28-.15-.68-.52-.01-.53.63-.01 1.08.58 1.23.82.72 1.21 1.87.87 2.33.66.07-.52.28-.87.51-1.07-1.78-.2-3.64-.89-3.64-3.95 0-.87.31-1.59.82-2.15-.08-.2-.36-1.02.08-2.12 0 0 .67-.21 2.2.82.64-.18 1.32-.27 2-.27.68 0 1.36.09 2 .27 1.53-1.04 2.2-.82 2.2-.82.44 1.1.16 1.92.08 2.12.51.56.82 1.27.82 2.15 0 3.07-1.87 3.75-3.65 3.95.29.25.54.73.54 1.48 0 1.07-.01 1.93-.01 2.2 0 .21.15.46.55.38A8.012 8.012 0 0 0 16 8c0-4.42-3.58-8-8-8z"></path></svg></a></div></div></nav><div class="wrap h1body-exist max-container"><header class="wrap-header h1wrap"><h1 id="docker-备忘清单"><svg xmlns="http://www.w3.org/2000/svg" fill="currentColor" viewBox="0 0 640 512" height="1em" width="1em">
  <path d="M349.9 236.3h-66.1v-59.4h66.1v59.4zm0-204.3h-66.1v60.7h66.1V32zm78.2 144.8H362v59.4h66.1v-59.4zm-156.3-72.1h-66.1v60.1h66.1v-60.1zm78.1 0h-66.1v60.1h66.1v-60.1zm276.8 100c-14.4-9.7-47.6-13.2-73.1-8.4-3.3-24-16.7-44.9-41.1-63.7l-14-9.3-9.3 14c-18.4 27.8-23.4 73.6-3.7 103.8-8.7 4.7-25.8 11.1-48.4 10.7H2.4c-8.7 50.8 5.8 116.8 44 162.1 37.1 43.9 92.7 66.2 165.4 66.2 157.4 0 273.9-72.5 328.4-204.2 21.4.4 67.6.1 91.3-45.2 1.5-2.5 6.6-13.2 8.5-17.1l-13.3-8.9zm-511.1-27.9h-66v59.4h66.1v-59.4zm78.1 0h-66.1v59.4h66.1v-59.4zm78.1 0h-66.1v59.4h66.1v-59.4zm-78.1-72.1h-66.1v60.1h66.1v-60.1z"></path>
</svg>
<a aria-hidden="true" tabindex="-1" href="#docker-备忘清单"><span class="icon icon-link"></span></a>Docker 备忘清单</h1><div class="wrap-body">
<p>这是 <a href="https://docs.docker.com/get-started/">Docker</a> 的快速参考备忘单。 你可以在这里找到最常见的 Docker 命令。</p>
</div></header><div class="menu-tocs"><div class="menu-btn"><svg aria-hidden="true" fill="currentColor" height="1em" width="1em" viewBox="0 0 16 16" version="1.1" data-view-component="true">
  <path fill-rule="evenodd" d="M2 4a1 1 0 100-2 1 1 0 000 2zm3.75-1.5a.75.75 0 000 1.5h8.5a.75.75 0 000-1.5h-8.5zm0 5a.75.75 0 000 1.5h8.5a.75.75 0 000-1.5h-8.5zm0 5a.75.75 0 000 1.5h8.5a.75.75 0 000-1.5h-8.5zM3 8a1 1 0 11-2 0 1 1 0 012 0zm-1 6a1 1 0 100-2 1 1 0 000 2z"></path>
</svg></div><div class="menu-modal"><a aria-hidden="true" class="leve2 tocs-link" data-num="2" href="#入门">入门</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#入门-1">入门</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#一般命令">一般命令</a><a aria-hidden="true" class="leve2 tocs-link" data-num="2" href="#docker-容器">Docker 容器</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#启动和停止">启动和停止</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#说明">说明</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#创建容器">创建容器</a><a aria-hidden="true" class="leve4 tocs-link" data-num="4" href="#实例">实例</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#操控">操控</a><a aria-hidden="true" class="leve2 tocs-link" data-num="2" href="#docker-镜像">Docker 镜像</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#操控-1">操控</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#构建镜像">构建镜像</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#删除-none-镜像">删除 &#x3C;none> 镜像</a><a aria-hidden="true" class="leve2 tocs-link" data-num="2" href="#docker-网络">Docker 网络</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#操作">操作</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#创建网络">创建网络</a><a aria-hidden="true" class="leve2 tocs-link" data-num="2" href="#docker-快捷键">Docker 快捷键</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#退出">退出</a><a aria-hidden="true" class="leve2 tocs-link" data-num="2" href="#各种各样的">各种各样的</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#docker-hub">Docker Hub</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#镜像仓库命令">镜像仓库命令</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#批量清除">批量清除</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#卷-volume">卷 volume</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#docker-compose">Docker Compose</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#docker-services">Docker Services</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#docker-stack">Docker Stack</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#docker-machine">Docker Machine</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#docker-主要命令">docker 主要命令</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#docker-runcreate">docker run/create</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#docker-全局参数">docker 全局参数</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#docker-管理命令">docker 管理命令</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#docker-images">docker images</a><a aria-hidden="true" class="leve2 tocs-link" data-num="2" href="#docker-示例">Docker 示例</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#docker-web-管理工具-portainer">Docker Web 管理工具 portainer</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#在线代码编辑器-code-server">在线代码编辑器 Code Server</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#mysql">MySQL</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#redis">Redis</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#nginx">Nginx</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#postgresql">PostgreSQL</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#媒体管理工具-dim">媒体管理工具 Dim</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#gitlab">Gitlab</a><a aria-hidden="true" class="leve2 tocs-link" data-num="2" href="#另见">另见</a></div></div><div class="h1wrap-body"><div class="wrap h2body-exist"><div class="wrap-header h2wrap"><h2 id="入门"><a aria-hidden="true" tabindex="-1" href="#入门"><span class="icon icon-link"></span></a>入门</h2><div class="wrap-body">
<!--rehype:body-class=cols-2-->
</div></div><div class="h2wrap-body cols-2"><div class="wrap h3body-not-exist"><div class="wrap-header h3wrap"><h3 id="入门-1"><a aria-hidden="true" tabindex="-1" href="#入门-1"><span class="icon icon-link"></span></a>入门</h3><div class="wrap-body">
<p>在后台创建和运行容器</p>
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line">$ <span class="token function">docker</span> run <span class="token parameter variable">-d</span> <span class="token parameter variable">-p</span> <span class="token number">80</span>:80 docker/getting-started
</span></code></pre>
<hr>
<ul>
<li><code>-d</code> - 以分离（后台）模式运行容器</li>
<li><code>-p 80:80</code> -  将端口 80 映射到容器中的端口 80，格式：宿主机端口:容器端口</li>
<li><code>docker/getting-started</code> - 要使用的镜像</li>
</ul>
<p>在前台创建并运行容器（之后如果要退出容器但是不关闭容器，按<em>Ctrl+P+Q</em>即可）</p>
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line">$ <span class="token function">docker</span> run <span class="token parameter variable">-it</span> <span class="token parameter variable">--rm</span> <span class="token parameter variable">-p</span>  <span class="token number">8001</span>:8080 <span class="token parameter variable">--name</span> my-nginx nginx
</span></code></pre>
<hr>
<ul>
<li><code>-it</code> - 交互式 bash 模式</li>
<li><code>--rm</code> - 容器终止运行后自动删除容器文件</li>
<li><code>-p 8001:8080</code> - 将 <code>8001</code> 端口映射到容器中的 <code>8080</code> 端口</li>
<li><code>--name my-nginx</code> - 指定名称</li>
<li><code>nginx</code> - 要使用的镜像</li>
</ul>
</div></div></div><div class="wrap h3body-not-exist"><div class="wrap-header h3wrap"><h3 id="一般命令"><a aria-hidden="true" tabindex="-1" href="#一般命令"><span class="icon icon-link"></span></a>一般命令</h3><div class="wrap-body">

























































<table><thead><tr><th>Example</th><th>Description</th></tr></thead><tbody><tr><td><code>docker ps</code></td><td>列出正在运行的容器</td></tr><tr><td><code>docker ps -a</code></td><td>列出所有容器</td></tr><tr><td><code>docker ps -s</code></td><td>列出正在运行的容器 <em>(带 CPU / 内存)</em></td></tr><tr><td><code>docker images</code></td><td>列出所有镜像</td></tr><tr><td><code>docker exec -it &#x3C;container>  bash</code></td><td>连接到容器</td></tr><tr><td><code>docker logs &#x3C;container></code></td><td>显示容器的控制台日志</td></tr><tr><td><code>docker stop &#x3C;container></code></td><td>停止容器</td></tr><tr><td><code>docker restart &#x3C;container></code></td><td>重启一个容器</td></tr><tr><td><code>docker rm &#x3C;container></code></td><td>移除一个容器</td></tr><tr><td><code>docker port &#x3C;container></code></td><td>显示容器的端口映射</td></tr><tr><td><code>docker top &#x3C;container></code></td><td>列出进程</td></tr><tr><td><code>docker kill &#x3C;container></code></td><td>杀死一个容器</td></tr></tbody></table>
<p>参数 <code>&#x3C;container></code> 可以是容器 id 或名称</p>
</div></div></div></div></div><div class="wrap h2body-exist"><div class="wrap-header h2wrap"><h2 id="docker-容器"><a aria-hidden="true" tabindex="-1" href="#docker-容器"><span class="icon icon-link"></span></a>Docker 容器</h2><div class="wrap-body">
<!--rehype:body-class=cols-2-->
</div></div><div class="h2wrap-body cols-2"><div class="wrap h3body-not-exist"><div class="wrap-header h3wrap"><h3 id="启动和停止"><a aria-hidden="true" tabindex="-1" href="#启动和停止"><span class="icon icon-link"></span></a>启动和停止</h3><div class="wrap-body">









































<table><thead><tr><th>Description</th><th>Example</th></tr></thead><tbody><tr><td><code>docker start nginx-server</code></td><td>开始</td></tr><tr><td><code>docker stop nginx-server</code></td><td>停止</td></tr><tr><td><code>docker restart nginx-server</code></td><td>重启</td></tr><tr><td><code>docker pause nginx-server</code></td><td>暂停</td></tr><tr><td><code>docker unpause nginx-server</code></td><td>取消暂停</td></tr><tr><td><code>docker wait nginx-server</code></td><td>阻塞容器</td></tr><tr><td><code>docker kill nginx-server</code></td><td>发送 SIGKILL</td></tr><tr><td><code>docker attach nginx-server</code></td><td>连接到现有容器</td></tr></tbody></table>
</div></div></div><div class="wrap h3body-not-exist"><div class="wrap-header h3wrap"><h3 id="说明"><a aria-hidden="true" tabindex="-1" href="#说明"><span class="icon icon-link"></span></a>说明</h3><div class="wrap-body">













































<table><thead><tr><th>Example</th><th>Description</th></tr></thead><tbody><tr><td><code>docker ps</code></td><td>列出正在运行的容器</td></tr><tr><td><code>docker ps -a</code></td><td>列出所有容器</td></tr><tr><td><code>docker logs nginx-server</code></td><td>容器日志</td></tr><tr><td><code>docker inspect nginx-server</code></td><td>检查容器</td></tr><tr><td><code>docker events nginx-server</code></td><td>容器事件</td></tr><tr><td><code>docker port nginx-server</code></td><td>公共端口</td></tr><tr><td><code>docker top nginx-server</code></td><td>运行进程</td></tr><tr><td><code>docker stats nginx-server</code></td><td>容器资源使用</td></tr><tr><td><code>docker diff nginx-server</code></td><td>列出对容器所做的更改</td></tr></tbody></table>
</div></div></div><div class="wrap h3body-exist"><div class="wrap-header h3wrap"><h3 id="创建容器"><a aria-hidden="true" tabindex="-1" href="#创建容器"><span class="icon icon-link"></span></a>创建容器</h3><div class="wrap-body">
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line"><span class="token function">docker</span> create <span class="token punctuation">[</span>options<span class="token punctuation">]</span> IMAGE
</span><span class="code-line">  -a, <span class="token parameter variable">--attach</span>               <span class="token comment"># 附加标准输出/错误</span>
</span><span class="code-line">  -i, <span class="token parameter variable">--interactive</span>          <span class="token comment"># 附加标准输入（交互式）</span>
</span><span class="code-line">  -t, <span class="token parameter variable">--tty</span>                  <span class="token comment"># 伪终端 pseudo-tty</span>
</span><span class="code-line">      <span class="token parameter variable">--name</span> NAME            <span class="token comment"># 命名你的镜像</span>
</span><span class="code-line">  -p, <span class="token parameter variable">--publish</span> <span class="token number">5000</span>:5000    <span class="token comment"># 端口映射（主机:容器）</span>
</span><span class="code-line">      <span class="token parameter variable">--expose</span> <span class="token number">5432</span>          <span class="token comment"># 向容器公开端口 </span>
</span><span class="code-line">  -P, --publish-all          <span class="token comment"># 发布所有端口</span>
</span><span class="code-line">      <span class="token parameter variable">--link</span> container:alias <span class="token comment"># 链接 linking</span>
</span><span class="code-line">  -v, <span class="token parameter variable">--volume</span> <span class="token variable"><span class="token variable">`</span><span class="token builtin class-name">pwd</span><span class="token variable">`</span></span>:/app    <span class="token comment"># mount（需要绝对路径）</span>
</span><span class="code-line">  -e, <span class="token parameter variable">--env</span> <span class="token assign-left variable">NAME</span><span class="token operator">=</span>hello       <span class="token comment"># 环境变量 env vars</span>
</span></code></pre>
<h4 id="实例"><a aria-hidden="true" tabindex="-1" href="#实例"><span class="icon icon-link"></span></a>实例</h4>
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line">$ <span class="token function">docker</span> create <span class="token parameter variable">--name</span> my_redis <span class="token parameter variable">--expose</span> <span class="token number">6379</span> redis:3.0.2
</span></code></pre>
</div></div></div><div class="wrap h3body-not-exist"><div class="wrap-header h3wrap"><h3 id="操控"><a aria-hidden="true" tabindex="-1" href="#操控"><span class="icon icon-link"></span></a>操控</h3><div class="wrap-body">
<p>重命名容器</p>
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line"><span class="token function">docker</span> <span class="token function">rename</span> my-nginx nginx-server
</span></code></pre>
<p>移除容器</p>
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line"><span class="token function">docker</span> <span class="token function">rm</span> nginx-server
</span></code></pre>
<p>更新容器</p>
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line"><span class="token function">docker</span> update --cpu-shares <span class="token number">512</span> <span class="token parameter variable">-m</span> 300M nginx-server
</span></code></pre>
</div></div></div></div></div><div class="wrap h2body-exist"><div class="wrap-header h2wrap"><h2 id="docker-镜像"><a aria-hidden="true" tabindex="-1" href="#docker-镜像"><span class="icon icon-link"></span></a>Docker 镜像</h2><div class="wrap-body">
<!--rehype:body-class=cols-2-->
</div></div><div class="h2wrap-body cols-2"><div class="wrap h3body-not-exist row-span-2"><div class="wrap-header h3wrap"><h3 id="操控-1"><a aria-hidden="true" tabindex="-1" href="#操控-1"><span class="icon icon-link"></span></a>操控</h3><div class="wrap-body">
<!--rehype:wrap-class=row-span-2-->













































<table><thead><tr><th><code>Example</code></th><th>Description</th></tr></thead><tbody><tr><td><code>docker images</code></td><td>列出镜像</td></tr><tr><td><code>docker rmi nginx</code></td><td>删除镜像</td></tr><tr><td><code>docker load &#x3C; ubuntu.tar.gz</code></td><td>加载一个 tarred 存储库</td></tr><tr><td><code>docker load --input ubuntu.tar</code></td><td>加载一个 tarred 存储库</td></tr><tr><td><code>docker save busybox > ubuntu.tar</code></td><td>将镜像保存到 tar 存档</td></tr><tr><td><code>docker history</code></td><td>显示镜像的历史</td></tr><tr><td><code>docker commit nginx my_nginx</code></td><td>将容器另存为镜像</td></tr><tr><td><code>docker tag nginx eon01/nginx</code></td><td>标记镜像</td></tr><tr><td><code>docker push eon01/nginx</code></td><td>推送镜像</td></tr></tbody></table>
</div></div></div><div class="wrap h3body-not-exist"><div class="wrap-header h3wrap"><h3 id="构建镜像"><a aria-hidden="true" tabindex="-1" href="#构建镜像"><span class="icon icon-link"></span></a>构建镜像</h3><div class="wrap-body">
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line"><span class="token comment"># 注意有的最后面是英文 .</span>
</span><span class="code-line">$ <span class="token function">docker</span> build <span class="token builtin class-name">.</span>
</span><span class="code-line">$ <span class="token function">docker</span> build github.com/creack/docker-firefox
</span><span class="code-line">$ <span class="token function">docker</span> build - <span class="token operator">&#x3C;</span> Dockerfile
</span><span class="code-line">$ <span class="token function">docker</span> build - <span class="token operator">&#x3C;</span> context.tar.gz
</span><span class="code-line">$ <span class="token function">docker</span> build <span class="token parameter variable">-t</span> eon/nginx-server <span class="token builtin class-name">.</span>
</span><span class="code-line">$ <span class="token function">docker</span> build <span class="token parameter variable">-f</span> myOtherDockerfile <span class="token builtin class-name">.</span>
</span><span class="code-line">$ <span class="token function">curl</span> example.com/remote/Dockerfile <span class="token operator">|</span> <span class="token function">docker</span> build <span class="token parameter variable">-f</span> - <span class="token builtin class-name">.</span>
</span></code></pre>
</div></div></div><div class="wrap h3body-not-exist"><div class="wrap-header h3wrap"><h3 id="删除-none-镜像"><a aria-hidden="true" tabindex="-1" href="#删除-none-镜像"><span class="icon icon-link"></span></a>删除 &#x3C;none> 镜像</h3><div class="wrap-body">
<pre class="language-bash"><code class="language-bash code-highlight"><span class="code-line">$ <span class="token function">docker</span> rmi <span class="token parameter variable">-f</span> <span class="token variable"><span class="token variable">$(</span><span class="token function">docker</span> images <span class="token operator">|</span> <span class="token function">grep</span> <span class="token string">"none"</span> <span class="token operator">|</span> <span class="token function">awk</span> <span class="token string">'{print $3}'</span><span class="token variable">)</span></span>
</span></code></pre>
</div></div></div></div></div><div class="wrap h2body-exist"><div class="wrap-header h2wrap"><h2 id="docker-网络"><a aria-hidden="true" tabindex="-1" href="#docker-网络"><span class="icon icon-link"></span></a>Docker 网络</h2><div class="wrap-body">
<!--rehype:body-class=cols-2-->
</div></div><div class="h2wrap-body cols-2"><div class="wrap h3body-not-exist"><div class="wrap-header h3wrap"><h3 id="操作"><a aria-hidden="true" tabindex="-1" href="#操作"><span class="icon icon-link"></span></a>操作</h3><div class="wrap-body">
<p>获取容器连接的网络</p>
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line"><span class="token function">docker</span> inspect MyContainer <span class="token operator">|</span> <span class="token function">grep</span> Network
</span></code></pre>
<p>删除网络</p>
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line"><span class="token function">docker</span> network <span class="token function">rm</span> MyOverlayNetwork
</span></code></pre>
<p>列出网络</p>
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line"><span class="token function">docker</span> network <span class="token function">ls</span>
</span></code></pre>
<p>获取有关网络的信息</p>
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line"><span class="token function">docker</span> network inspect MyOverlayNetwork
</span></code></pre>
<p>将正在运行的容器连接到网络</p>
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line"><span class="token function">docker</span> network connect MyOverlayNetwork nginx
</span></code></pre>
<p>启动时将容器连接到网络</p>
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line"><span class="token function">docker</span> run <span class="token parameter variable">-it</span> <span class="token parameter variable">-d</span> <span class="token parameter variable">--network</span><span class="token operator">=</span>MyOverlayNetwork nginx
</span></code></pre>
<p>断开容器与网络的连接</p>
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line"><span class="token function">docker</span> network disconnect MyOverlayNetwork nginx
</span></code></pre>
</div></div></div><div class="wrap h3body-not-exist"><div class="wrap-header h3wrap"><h3 id="创建网络"><a aria-hidden="true" tabindex="-1" href="#创建网络"><span class="icon icon-link"></span></a>创建网络</h3><div class="wrap-body">
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line"><span class="token function">docker</span> network create <span class="token parameter variable">-d</span> overlay MyOverlayNetwork
</span><span class="code-line"><span class="token function">docker</span> network create <span class="token parameter variable">-d</span> bridge MyBridgeNetwork
</span><span class="code-line"><span class="token function">docker</span> network create <span class="token parameter variable">-d</span> overlay <span class="token punctuation">\</span>
</span><span class="code-line">  <span class="token parameter variable">--subnet</span><span class="token operator">=</span><span class="token number">192.168</span>.0.0/16 <span class="token punctuation">\</span>
</span><span class="code-line">  <span class="token parameter variable">--subnet</span><span class="token operator">=</span><span class="token number">192.170</span>.0.0/16 <span class="token punctuation">\</span>
</span><span class="code-line">  <span class="token parameter variable">--gateway</span><span class="token operator">=</span><span class="token number">192.168</span>.0.100 <span class="token punctuation">\</span>
</span><span class="code-line">  <span class="token parameter variable">--gateway</span><span class="token operator">=</span><span class="token number">192.170</span>.0.100 <span class="token punctuation">\</span>
</span><span class="code-line">  --ip-range<span class="token operator">=</span><span class="token number">192.168</span>.1.0/24 <span class="token punctuation">\</span>
</span><span class="code-line">  --aux-address<span class="token operator">=</span><span class="token string">"my-router=192.168.1.5"</span> <span class="token punctuation">\</span>
</span><span class="code-line">  --aux-address<span class="token operator">=</span><span class="token string">"my-switch=192.168.1.6"</span> <span class="token punctuation">\</span>
</span><span class="code-line">  --aux-address<span class="token operator">=</span><span class="token string">"my-printer=192.170.1.5"</span> <span class="token punctuation">\</span>
</span><span class="code-line">  --aux-address<span class="token operator">=</span><span class="token string">"my-nas=192.170.1.6"</span> <span class="token punctuation">\</span>
</span><span class="code-line">  MyOverlayNetwork
</span></code></pre>
</div></div></div></div></div><div class="wrap h2body-exist"><div class="wrap-header h2wrap"><h2 id="docker-快捷键"><a aria-hidden="true" tabindex="-1" href="#docker-快捷键"><span class="icon icon-link"></span></a>Docker 快捷键</h2><div class="wrap-body">
<!--rehype:body-class=cols-2-->
</div></div><div class="h2wrap-body cols-2"><div class="wrap h3body-not-exist"><div class="wrap-header h3wrap"><h3 id="退出"><a aria-hidden="true" tabindex="-1" href="#退出"><span class="icon icon-link"></span></a>退出</h3><div class="wrap-body">





















<table><thead><tr><th>Docker 快捷键</th><th>说明</th></tr></thead><tbody><tr><td><code>ctrl+c</code></td><td>将关闭容器，并删除当前的容器实例</td></tr><tr><td><code>ctrl+d</code></td><td>将保留容器，并退出到Docker主机的命令行界面</td></tr><tr><td><code>ctrl+p+q</code></td><td>将容器分离，保留容器，但是不退出</td></tr></tbody></table>
<p>需要特别注意的是，上面的退出快捷键中的删除容器实例只对于使用<code>docker attach</code>进入的容器生效，使用<code>docker exec</code>进入容器后使用上面的快捷键后将隔离容器且不会删除容器实例。</p>
</div></div></div></div></div><div class="wrap h2body-exist"><div class="wrap-header h2wrap"><h2 id="各种各样的"><a aria-hidden="true" tabindex="-1" href="#各种各样的"><span class="icon icon-link"></span></a>各种各样的</h2><div class="wrap-body">
<!--rehype:body-class=cols-2-->
</div></div><div class="h2wrap-body cols-2"><div class="wrap h3body-not-exist"><div class="wrap-header h3wrap"><h3 id="docker-hub"><a aria-hidden="true" tabindex="-1" href="#docker-hub"><span class="icon icon-link"></span></a>Docker Hub</h3><div class="wrap-body">

























<table><thead><tr><th>Docker 语法</th><th>说明</th></tr></thead><tbody><tr><td><code>docker search search_word</code></td><td>在 docker hub 中搜索镜像</td></tr><tr><td><code>docker pull user/image</code></td><td>从 docker hub 下载镜像</td></tr><tr><td><code>docker login</code></td><td>向 docker hub 进行身份验证</td></tr><tr><td><code>docker push user/image</code></td><td>将镜像上传到 docker hub</td></tr></tbody></table>
</div></div></div><div class="wrap h3body-not-exist row-span-3"><div class="wrap-header h3wrap"><h3 id="镜像仓库命令"><a aria-hidden="true" tabindex="-1" href="#镜像仓库命令"><span class="icon icon-link"></span></a>镜像仓库命令</h3><div class="wrap-body">
<!--rehype:wrap-class=row-span-3-->
<p>登录到镜像仓库</p>
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line">$ <span class="token function">docker</span> login
</span><span class="code-line">$ <span class="token function">docker</span> login localhost:8080
</span></code></pre>
<p>从镜像仓库注销</p>
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line">$ <span class="token function">docker</span> <span class="token builtin class-name">logout</span>
</span><span class="code-line">$ <span class="token function">docker</span> <span class="token builtin class-name">logout</span> localhost:8080
</span></code></pre>
<p>搜索镜像</p>
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line">$ <span class="token function">docker</span> search nginx
</span><span class="code-line">$ <span class="token function">docker</span> search nginx <span class="token parameter variable">--stars</span><span class="token operator">=</span><span class="token number">3</span> --no-trunc busybox
</span></code></pre>
<p>拉取镜像</p>
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line">$ <span class="token function">docker</span> pull nginx
</span><span class="code-line">$ <span class="token function">docker</span> pull eon01/nginx localhost:5000/myadmin/nginx
</span></code></pre>
<p>推送镜像</p>
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line">$ <span class="token function">docker</span> push eon01/nginx
</span><span class="code-line">$ <span class="token function">docker</span> push eon01/nginx localhost:5000/myadmin/nginx
</span></code></pre>
</div></div></div><div class="wrap h3body-not-exist"><div class="wrap-header h3wrap"><h3 id="批量清除"><a aria-hidden="true" tabindex="-1" href="#批量清除"><span class="icon icon-link"></span></a>批量清除</h3><div class="wrap-body">





















<table><thead><tr><th>实例</th><th>说明</th></tr></thead><tbody><tr><td><code>docker stop -f $(docker ps -a -q)</code></td><td>停止所有容器</td></tr><tr><td><code>docker rm -f $(docker ps -a -q)</code></td><td>删除所有容器</td></tr><tr><td><code>docker rmi -f $(docker images -q)</code></td><td>删除所有镜像</td></tr></tbody></table>
</div></div></div><div class="wrap h3body-not-exist"><div class="wrap-header h3wrap"><h3 id="卷-volume"><a aria-hidden="true" tabindex="-1" href="#卷-volume"><span class="icon icon-link"></span></a>卷 volume</h3><div class="wrap-body">
<p>检查卷</p>
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line">$ <span class="token function">docker</span> volume <span class="token function">ls</span>
</span></code></pre>
<p>清理未使用的卷</p>
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line">$ <span class="token function">docker</span> volume prune
</span></code></pre>
</div></div></div><div class="wrap h3body-not-exist col-span-2"><div class="wrap-header h3wrap"><h3 id="docker-compose"><a aria-hidden="true" tabindex="-1" href="#docker-compose"><span class="icon icon-link"></span></a>Docker Compose</h3><div class="wrap-body">
<!--rehype:wrap-class=col-span-2-->





















































<table><thead><tr><th align="left">:-</th><th align="left">:-</th></tr></thead><tbody><tr><td align="left"><code>docker-compose up</code></td><td align="left">创建和启动容器</td></tr><tr><td align="left"><code>docker-compose up -d</code></td><td align="left">以分离模式创建和启动容器</td></tr><tr><td align="left"><code>docker-compose down</code></td><td align="left">停止和删除容器、网络、映像和卷</td></tr><tr><td align="left"><code>docker-compose logs</code></td><td align="left">查看容器的输出</td></tr><tr><td align="left"><code>docker-compose restart</code></td><td align="left">重启所有服务</td></tr><tr><td align="left"><code>docker-compose pull</code></td><td align="left">拉取所有服务的镜像</td></tr><tr><td align="left"><code>docker-compose build</code></td><td align="left">构建所有服务的镜像</td></tr><tr><td align="left"><code>docker-compose config</code></td><td align="left">验证并查看 Compose 文件</td></tr><tr><td align="left"><code>docker-compose scale &#x3C;service_name>=&#x3C;replica></code></td><td align="left">为服务指定容器个数</td></tr><tr><td align="left"><code>docker-compose top</code></td><td align="left">显示正在运行的进程</td></tr><tr><td align="left"><code>docker-compose run -rm -p 2022:22 web bash</code></td><td align="left">启动 Web 服务并运行 bash 作为其命令，删除旧容器</td></tr></tbody></table>
</div></div></div><div class="wrap h3body-not-exist"><div class="wrap-header h3wrap"><h3 id="docker-services"><a aria-hidden="true" tabindex="-1" href="#docker-services"><span class="icon icon-link"></span></a>Docker Services</h3><div class="wrap-body">

































<table class="left-align"><thead><tr><th align="left">:-</th><th align="left">:-</th></tr></thead><tbody><tr><td align="left"><code>docker service create &#x3C;options> &#x3C;image> &#x3C;command></code></td><td align="left">创建新服务</td></tr><tr><td align="left"><code>docker service inspect --pretty &#x3C;service_name></code></td><td align="left">显示详细信息服务</td></tr><tr><td align="left"><code>docker service ls</code></td><td align="left">列出服务</td></tr><tr><td align="left"><code>docker service ps</code></td><td align="left">列出服务的任务</td></tr><tr><td align="left"><code>docker service scale &#x3C;service_name>=&#x3C;replica></code></td><td align="left">规模特殊服务</td></tr><tr><td align="left"><code>docker service update &#x3C;options> &#x3C;service_name></code></td><td align="left">更新服务选项</td></tr></tbody></table>
<!--rehype:className=left-align-->
</div></div></div><div class="wrap h3body-not-exist"><div class="wrap-header h3wrap"><h3 id="docker-stack"><a aria-hidden="true" tabindex="-1" href="#docker-stack"><span class="icon icon-link"></span></a>Docker Stack</h3><div class="wrap-body">





























<table class="left-align"><thead><tr><th align="left">:-</th><th align="left">:-</th></tr></thead><tbody><tr><td align="left"><code>docker stack ls</code></td><td align="left">列出此 Docker 主机上所有正在运行的应用程序</td></tr><tr><td align="left"><code>docker stack deploy -c &#x3C;composefile> &#x3C;appname></code></td><td align="left">运行指定的 Compose 文件</td></tr><tr><td align="left"><code>docker stack services &#x3C;appname></code></td><td align="left">列出与应用关联的服务</td></tr><tr><td align="left"><code>docker stack ps &#x3C;appname></code></td><td align="left">列出与应用关联的正在运行的容器</td></tr><tr><td align="left"><code>docker stack rm &#x3C;appname></code></td><td align="left">拆掉一个应用程序</td></tr></tbody></table>
<!--rehype:className=left-align-->
</div></div></div><div class="wrap h3body-not-exist col-span-2"><div class="wrap-header h3wrap"><h3 id="docker-machine"><a aria-hidden="true" tabindex="-1" href="#docker-machine"><span class="icon icon-link"></span></a>Docker Machine</h3><div class="wrap-body">
<!--rehype:wrap-class=col-span-2-->

































































<table class="left-align"><thead><tr><th align="left">:-</th><th align="left">:-</th></tr></thead><tbody><tr><td align="left"><code>docker-machine create --driver virtualbox myvm1</code></td><td align="left">创建虚拟机（Mac、Win7、Linux）</td></tr><tr><td align="left"><code>docker-machine create -d hyperv --hyperv-virtual-switch "myswitch" myvm1</code></td><td align="left">Win10</td></tr><tr><td align="left"><code>docker-machine env myvm1</code></td><td align="left">查看有关您的节点的基本信息</td></tr><tr><td align="left"><code>docker-machine ssh myvm1 "docker node ls"</code></td><td align="left">列出集群中的节点</td></tr><tr><td align="left"><code>docker-machine ssh myvm1 "docker node inspect &#x3C;node ID>"</code></td><td align="left">检查节点</td></tr><tr><td align="left"><code>docker-machine ssh myvm1 "docker swarm join-token -q worker"</code></td><td align="left">查看加入令牌</td></tr><tr><td align="left"><code>docker-machine ssh myvm1</code></td><td align="left">打开与 VM 的 SSH 会话； 输入“exit”结束</td></tr><tr><td align="left"><code>docker-machine ssh myvm2 "docker swarm leave"</code></td><td align="left">让工人离开群体</td></tr><tr><td align="left"><code>docker-machine ssh myvm1 "docker swarm leave -f"</code></td><td align="left">让主人离开，杀群</td></tr><tr><td align="left"><code>docker-machine start myvm1</code></td><td align="left">启动当前未运行的 VM</td></tr><tr><td align="left"><code>docker-machine stop $(docker-machine ls -q)</code></td><td align="left">停止所有正在运行的虚拟机</td></tr><tr><td align="left"><code>docker-machine rm $(docker-machine ls -q)</code></td><td align="left">删除所有虚拟机及其磁盘映像</td></tr><tr><td align="left"><code>docker-machine scp docker-compose.yml myvm1:~</code></td><td align="left">将文件复制到节点的主目录</td></tr><tr><td align="left"><code>docker-machine ssh myvm1 "docker stack deploy -c &#x3C;file> &#x3C;app>"</code></td><td align="left">部署应用</td></tr></tbody></table>
<!--rehype:className=left-align-->
</div></div></div><div class="wrap h3body-not-exist"><div class="wrap-header h3wrap"><h3 id="docker-主要命令"><a aria-hidden="true" tabindex="-1" href="#docker-主要命令"><span class="icon icon-link"></span></a>docker 主要命令</h3><div class="wrap-body">









































































































































































<table class="left-align"><thead><tr><th align="left">:-</th><th align="left">:-</th></tr></thead><tbody><tr><td align="left"><code>attach</code></td><td align="left">将本地标准输入、输出和错误流附加到正在运行的容器</td></tr><tr><td align="left"><code>build</code></td><td align="left">从 Dockerfile 构建镜像</td></tr><tr><td align="left"><code>commit</code></td><td align="left">从容器的更改创建新镜像</td></tr><tr><td align="left"><code>cp</code></td><td align="left">在容器和本地文件系统之间复制文件/文件夹</td></tr><tr><td align="left"><code>create</code></td><td align="left">创建一个新容器</td></tr><tr><td align="left"><code>diff</code></td><td align="left">检查容器文件系统上文件或目录的更改</td></tr><tr><td align="left"><code>events</code></td><td align="left">从服务器获取实时事件</td></tr><tr><td align="left"><code>exec</code></td><td align="left">在正在运行的容器中运行命令</td></tr><tr><td align="left"><code>export</code></td><td align="left">将容器的文件系统导出为 tar 存档</td></tr><tr><td align="left"><code>history</code></td><td align="left">显示镜像的历史</td></tr><tr><td align="left"><code>images</code></td><td align="left">列出镜像</td></tr><tr><td align="left"><code>import</code></td><td align="left">从 tarball 导入内容以创建文件系统映像</td></tr><tr><td align="left"><code>info</code></td><td align="left">显示系统范围的信息</td></tr><tr><td align="left"><code>inspect</code></td><td align="left">返回有关 Docker 对象的低级信息</td></tr><tr><td align="left"><code>kill</code></td><td align="left">杀死一个或多个正在运行的容器</td></tr><tr><td align="left"><code>load</code></td><td align="left">从 tar 存档或 STDIN 加载镜像</td></tr><tr><td align="left"><code>login</code></td><td align="left">登录到 Docker 注册表</td></tr><tr><td align="left"><code>logout</code></td><td align="left">从 Docker 注册表中注销</td></tr><tr><td align="left"><code>logs</code></td><td align="left">获取容器的日志</td></tr><tr><td align="left"><code>pause</code></td><td align="left">暂停一个或多个容器内的所有进程</td></tr><tr><td align="left"><code>port</code></td><td align="left">列出容器的端口映射或特定映射</td></tr><tr><td align="left"><code>ps</code></td><td align="left">列出容器</td></tr><tr><td align="left"><code>pull</code></td><td align="left">从注册表中提取镜像或存储库</td></tr><tr><td align="left"><code>push</code></td><td align="left">将镜像或存储库推送到注册表</td></tr><tr><td align="left"><code>rename</code></td><td align="left">重命名容器</td></tr><tr><td align="left"><code>restart</code></td><td align="left">重启一个或多个容器</td></tr><tr><td align="left"><code>rm</code></td><td align="left">移除一个或多个容器</td></tr><tr><td align="left"><code>rmi</code></td><td align="left">移除一张或多张镜像</td></tr><tr><td align="left"><code>run</code></td><td align="left">在新容器中运行命令</td></tr><tr><td align="left"><code>save</code></td><td align="left">将一个或多个镜像保存到 tar 存档（默认流式传输到 STDOUT）</td></tr><tr><td align="left"><code>search</code></td><td align="left">在 <code>Docker Hub</code> 中搜索镜像</td></tr><tr><td align="left"><code>start</code></td><td align="left">启动一个或多个停止的容器</td></tr><tr><td align="left"><code>stats</code></td><td align="left">显示容器资源使用统计的实时流</td></tr><tr><td align="left"><code>stop</code></td><td align="left">停止一个或多个正在运行的容器</td></tr><tr><td align="left"><code>tag</code></td><td align="left">创建一个引用 SOURCE_IMAGE 的标记 TARGET_IMAGE</td></tr><tr><td align="left"><code>top</code></td><td align="left">显示容器的运行进程</td></tr><tr><td align="left"><code>unpause</code></td><td align="left">取消暂停一个或多个容器中的所有进程</td></tr><tr><td align="left"><code>update</code></td><td align="left">更新一个或多个容器的配置</td></tr><tr><td align="left"><code>version</code></td><td align="left">显示 Docker 版本信息</td></tr><tr><td align="left"><code>wait</code></td><td align="left">阻塞直到一个或多个容器停止，然后打印它们的退出代码</td></tr></tbody></table>
<!--rehype:className=left-align-->
</div></div></div><div class="wrap h3body-not-exist row-span-3"><div class="wrap-header h3wrap"><h3 id="docker-runcreate"><a aria-hidden="true" tabindex="-1" href="#docker-runcreate"><span class="icon icon-link"></span></a>docker run/create</h3><div class="wrap-body">
<!--rehype:wrap-class=row-span-3-->
<pre class="language-bash"><code class="language-bash code-highlight"><span class="code-line">    --add-host list            <span class="token comment"># 添加自定义主机到 IP 映射 (host:ip)</span>
</span><span class="code-line">-a, <span class="token parameter variable">--attach</span> list              <span class="token comment"># 连接到 STDIN、STDOUT 或 STDERR</span>
</span><span class="code-line">    --blkio-weight uint16      <span class="token comment"># 块 IO（相对权重），介于 10 和 1000 之间，或 0 禁用（默认 0）</span>
</span><span class="code-line">    --blkio-weight-device list <span class="token comment"># 块 IO 权重（相对设备权重）（默认 []）</span>
</span><span class="code-line">    --cap-add list             <span class="token comment"># 添加 Linux 功能</span>
</span><span class="code-line">    --cap-drop list            <span class="token comment"># 放弃 Linux 功能</span>
</span><span class="code-line">    --cgroup-parent string     <span class="token comment"># 容器的可选父 cgroup</span>
</span><span class="code-line">    <span class="token parameter variable">--cgroupns</span> string   <span class="token comment"># 要使用的 Cgroup 命名空间（主机|私有）</span>
</span><span class="code-line">                        <span class="token comment">#  'host':    在 Docker 主机的 cgroup 命名空间中运行容器</span>
</span><span class="code-line">                        <span class="token comment">#  'private': 在自己的私有 cgroup 命名空间中运行容器</span>
</span><span class="code-line">                        <span class="token comment">#  '':        使用由守护进程上的 </span>
</span><span class="code-line">                        <span class="token comment">#        default-cgroupns-mode 选项配置的 cgroup 命名空间（默认）</span>
</span><span class="code-line">    <span class="token parameter variable">--cidfile</span> string           <span class="token comment"># 将容器 ID 写入文件</span>
</span><span class="code-line">    --cpu-period int           <span class="token comment"># 限制 CPU CFS（完全公平调度器）周期</span>
</span><span class="code-line">    --cpu-quota int            <span class="token comment"># 限制 CPU CFS（完全公平调度器）配额</span>
</span><span class="code-line">    --cpu-rt-period int        <span class="token comment"># 以微秒为单位限制 CPU 实时周期</span>
</span><span class="code-line">    --cpu-rt-runtime int       <span class="token comment"># 以微秒为单位限制 CPU 实时运行时间</span>
</span><span class="code-line">-c, --cpu-shares int           <span class="token comment"># CPU 份额（相对权重）</span>
</span><span class="code-line">    <span class="token parameter variable">--cpus</span> decimal             <span class="token comment"># CPU 数量</span>
</span><span class="code-line">    --cpuset-cpus string       <span class="token comment"># 允许执行的 CPU (0-3, 0,1)</span>
</span><span class="code-line">    --cpuset-mems string       <span class="token comment"># 允许执行的 MEM (0-3, 0,1)</span>
</span><span class="code-line">    <span class="token parameter variable">--device</span> list              <span class="token comment"># 将主机设备添加到容器</span>
</span><span class="code-line">    --device-cgroup-rule list  <span class="token comment"># 将规则添加到 cgroup 允许的设备列表</span>
</span><span class="code-line">    --device-read-bps list     <span class="token comment"># 限制设备的读取速率（每秒字节数）（默认 []）</span>
</span><span class="code-line">    --device-read-iops list    <span class="token comment"># 限制设备的读取速率（每秒 IO）（默认 []）</span>
</span><span class="code-line">    --device-write-bps list    <span class="token comment"># 限制设备的写入速率（每秒字节数）（默认 []）</span>
</span><span class="code-line">    --device-write-iops list   <span class="token comment"># 限制设备的写入速率（每秒 IO）（默认 []）</span>
</span><span class="code-line">    --disable-content-trust    <span class="token comment"># 跳过镜像验证（默认为 true）</span>
</span><span class="code-line">    <span class="token parameter variable">--dns</span> list                 <span class="token comment"># 设置自定义 DNS 服务器</span>
</span><span class="code-line">    --dns-option list          <span class="token comment"># 设置 DNS 选项</span>
</span><span class="code-line">    --dns-search list          <span class="token comment"># 设置自定义 DNS 搜索域</span>
</span><span class="code-line">    <span class="token parameter variable">--domainname</span> string        <span class="token comment"># 容器 NIS 域名</span>
</span><span class="code-line">    <span class="token parameter variable">--entrypoint</span> string        <span class="token comment"># 覆盖镜像的默认入口点</span>
</span><span class="code-line">-e, <span class="token parameter variable">--env</span> list                 <span class="token comment"># 设置环境变量</span>
</span><span class="code-line">    --env-file list            <span class="token comment"># 读入环境变量文件</span>
</span><span class="code-line">    <span class="token parameter variable">--expose</span> list              <span class="token comment"># 公开一个端口或一系列端口</span>
</span><span class="code-line">    <span class="token parameter variable">--gpus</span> gpu-request         <span class="token comment"># 要添加到容器中的 GPU 设备（“全部”以传递所有 GPU）</span>
</span><span class="code-line">    --group-add list           <span class="token comment"># 添加其他组以加入</span>
</span><span class="code-line">    --health-cmd string        <span class="token comment"># 运行以检查运行状况的命令</span>
</span><span class="code-line">    --health-interval duration <span class="token comment"># 运行检查之间的时间 (ms|s|m|h) (默认 0s)</span>
</span><span class="code-line">    --health-retries int           <span class="token comment"># 需要报告不健康的连续失败</span>
</span><span class="code-line">    --health-start-period duration <span class="token comment"># 开始健康重试倒计时之前容器初始化的开始时间（ms|s|m|h）（默认 0s）</span>
</span><span class="code-line">    --health-timeout duration      <span class="token comment"># 允许运行一项检查的最长时间 (ms|s|m|h) (默认 0s)</span>
</span><span class="code-line">    <span class="token parameter variable">--help</span>                     <span class="token comment"># 打印使用</span>
</span><span class="code-line">-h, <span class="token parameter variable">--hostname</span> string          <span class="token comment"># 容器主机名</span>
</span><span class="code-line">    <span class="token parameter variable">--init</span>                     <span class="token comment"># 在容器内运行一个 init 来转发信号并收获进程</span>
</span><span class="code-line">-i, <span class="token parameter variable">--interactive</span>              <span class="token comment"># 即使没有连接，也保持 STDIN 打开</span>
</span><span class="code-line">    <span class="token parameter variable">--ip</span> string                <span class="token comment"># IPv4 地址（例如 172.30.100.104）</span>
</span><span class="code-line">    <span class="token parameter variable">--ip6</span> string               <span class="token comment"># IPv6 地址（例如，2001:db8::33）</span>
</span><span class="code-line">    <span class="token parameter variable">--ipc</span> string               <span class="token comment"># 要使用的 IPC 模式</span>
</span><span class="code-line">    <span class="token parameter variable">--isolation</span> string         <span class="token comment"># 容器隔离技术</span>
</span><span class="code-line">    --kernel-memory bytes      <span class="token comment"># 内核内存限制</span>
</span><span class="code-line">-l, <span class="token parameter variable">--label</span> list               <span class="token comment"># 在容器上设置元数据</span>
</span><span class="code-line">    --label-file list          <span class="token comment"># 读入以行分隔的标签文件</span>
</span><span class="code-line">    <span class="token parameter variable">--link</span> list                <span class="token comment"># 添加到另一个容器的链接</span>
</span><span class="code-line">    --link-local-ip list       <span class="token comment"># 容器 IPv4/IPv6 链路本地地址</span>
</span><span class="code-line">    --log-driver string        <span class="token comment"># 容器的日志记录驱动程序</span>
</span><span class="code-line">    --log-opt list             <span class="token comment"># 日志驱动程序选项</span>
</span><span class="code-line">    --mac-address string       <span class="token comment"># 容器 MAC 地址（例如 92:d0:c6:0a:29:33）</span>
</span><span class="code-line">-m, <span class="token parameter variable">--memory</span> bytes             <span class="token comment"># 内存限制</span>
</span><span class="code-line">    --memory-reservation bytes <span class="token comment"># 内存软限制</span>
</span><span class="code-line">    --memory-swap bytes        <span class="token comment"># 交换限制等于内存加上交换：'-1' 启用无限交换</span>
</span><span class="code-line">    --memory-swappiness int    <span class="token comment"># 调整容器内存交换（0 到 100）（默认 -1）</span>
</span><span class="code-line">    <span class="token parameter variable">--mount</span> <span class="token function">mount</span>              <span class="token comment"># 将文件系统挂载附加到容器</span>
</span><span class="code-line">    <span class="token parameter variable">--name</span> string              <span class="token comment"># 为容器分配名称</span>
</span><span class="code-line">    <span class="token parameter variable">--network</span> network          <span class="token comment"># 将容器连接到网络</span>
</span><span class="code-line">    --network-alias list       <span class="token comment"># 为容器添加网络范围的别名</span>
</span><span class="code-line">    --no-healthcheck           <span class="token comment"># 禁用任何容器指定的 HEALTHCHECK</span>
</span><span class="code-line">    --oom-kill-disable         <span class="token comment"># 禁用 OOM 杀手</span>
</span><span class="code-line">    --oom-score-adj int        <span class="token comment"># 调整主机的 OOM 首选项（-1000 到 1000）</span>
</span><span class="code-line">    <span class="token parameter variable">--pid</span> string               <span class="token comment"># 要使用的 PID 命名空间</span>
</span><span class="code-line">    --pids-limit int           <span class="token comment"># 调整容器 pids 限制（设置 -1 表示无限制）</span>
</span><span class="code-line">    <span class="token parameter variable">--platform</span> string          <span class="token comment"># 如果服务器支持多平台，则设置平台</span>
</span><span class="code-line">    <span class="token parameter variable">--privileged</span>               <span class="token comment"># 授予此容器扩展权限</span>
</span><span class="code-line">-p, <span class="token parameter variable">--publish</span> list             <span class="token comment"># 将容器的端口发布到主机</span>
</span><span class="code-line">-P, --publish-all              <span class="token comment"># 将所有暴露的端口发布到随机端口</span>
</span><span class="code-line">    <span class="token parameter variable">--pull</span> string              <span class="token comment"># 创建前拉取镜像("always"|"missing"|"never")(默认"missing")</span>
</span><span class="code-line">    --read-only                <span class="token comment"># 将容器的根文件系统挂载为只读</span>
</span><span class="code-line">    <span class="token parameter variable">--restart</span> string           <span class="token comment"># 容器退出时应用的重启策略（默认“否”）</span>
</span><span class="code-line">    <span class="token parameter variable">--rm</span>                       <span class="token comment"># 容器退出时自动移除</span>
</span><span class="code-line">    <span class="token parameter variable">--runtime</span> string           <span class="token comment"># 用于此容器的运行时</span>
</span><span class="code-line">    --security-opt list        <span class="token comment"># 安全选项</span>
</span><span class="code-line">    --shm-size bytes           <span class="token comment"># /dev/shm 的大小</span>
</span><span class="code-line">    --stop-signal string       <span class="token comment"># 停止容器的信号（默认“SIGTERM”）</span>
</span><span class="code-line">    --stop-timeout int         <span class="token comment"># 停止容器的超时（以秒为单位）</span>
</span><span class="code-line">    --storage-opt list         <span class="token comment"># 容器的存储驱动程序选项</span>
</span><span class="code-line">    <span class="token parameter variable">--sysctl</span> map               <span class="token comment"># Sysctl 选项（默认 map[]）</span>
</span><span class="code-line">    <span class="token parameter variable">--tmpfs</span> list               <span class="token comment"># 挂载 tmpfs 目录</span>
</span><span class="code-line">-t, <span class="token parameter variable">--tty</span>                      <span class="token comment"># 分配一个伪 TTY</span>
</span><span class="code-line">    <span class="token parameter variable">--ulimit</span> <span class="token builtin class-name">ulimit</span>            <span class="token comment"># ulimit 选项（默认 []）</span>
</span><span class="code-line">-u, <span class="token parameter variable">--user</span> string              <span class="token comment"># 用户名或 UID（格式：&#x3C;name|uid>[:&#x3C;group|gid>]）</span>
</span><span class="code-line">    <span class="token parameter variable">--userns</span> string            <span class="token comment"># 要使用的用户命名空间</span>
</span><span class="code-line">    <span class="token parameter variable">--uts</span> string               <span class="token comment"># 要使用的 UTS 命名空间</span>
</span><span class="code-line">-v, <span class="token parameter variable">--volume</span> list              <span class="token comment"># 绑定挂载卷</span>
</span><span class="code-line">    --volume-driver string     <span class="token comment"># 容器的可选卷驱动程序</span>
</span><span class="code-line">    --volumes-from list        <span class="token comment"># 从指定容器挂载卷</span>
</span><span class="code-line">-w, <span class="token parameter variable">--workdir</span> string           <span class="token comment"># 容器内的工作目录</span>
</span></code></pre>
<p><code>run</code>/<code>create</code> 大部分参数一致</p>
</div></div></div><div class="wrap h3body-not-exist"><div class="wrap-header h3wrap"><h3 id="docker-全局参数"><a aria-hidden="true" tabindex="-1" href="#docker-全局参数"><span class="icon icon-link"></span></a>docker 全局参数</h3><div class="wrap-body">
<pre class="language-bash"><code class="language-bash code-highlight"><span class="code-line">    <span class="token parameter variable">--config</span> string     <span class="token comment"># 客户端配置文件的位置（默认“~/.docker”）</span>
</span><span class="code-line">-c, <span class="token parameter variable">--context</span> string    <span class="token comment"># 用于连接到守护程序的上下文的名称（</span>
</span><span class="code-line">                        <span class="token comment"># 覆盖 DOCKER_HOST 环境变量和使用“docker context use”设置的默认上下文）</span>
</span><span class="code-line">-D, <span class="token parameter variable">--debug</span>             <span class="token comment"># 启用调试模式</span>
</span><span class="code-line">-H, <span class="token parameter variable">--host</span> list         <span class="token comment"># 要连接的守护进程套接字</span>
</span><span class="code-line">-l, --log-level string  <span class="token comment"># 设置日志级别("debug"\|"info"\|"warn"\|"error"\|"fatal") （默认“info”）</span>
</span><span class="code-line">    <span class="token parameter variable">--tls</span>               <span class="token comment"># 使用 TLS； 由 --tlsverify 暗示</span>
</span><span class="code-line">    <span class="token parameter variable">--tlscacert</span> string  <span class="token comment"># 仅由该 CA 签署的信任证书（默认为“~/.docker/ca.pem”）</span>
</span><span class="code-line">    <span class="token parameter variable">--tlscert</span> string    <span class="token comment"># TLS证书文件路径（默认“~/.docker/cert.pem”）</span>
</span><span class="code-line">    <span class="token parameter variable">--tlskey</span> string     <span class="token comment"># TLS 密钥文件的路径（默认为“~/.docker/key.pem”）</span>
</span><span class="code-line">    <span class="token parameter variable">--tlsverify</span>         <span class="token comment"># 使用 TLS 并验证远程</span>
</span><span class="code-line">-v, <span class="token parameter variable">--version</span>           <span class="token comment"># 打印版本信息并退出</span>
</span></code></pre>
</div></div></div><div class="wrap h3body-not-exist row-span-2"><div class="wrap-header h3wrap"><h3 id="docker-管理命令"><a aria-hidden="true" tabindex="-1" href="#docker-管理命令"><span class="icon icon-link"></span></a>docker 管理命令</h3><div class="wrap-body">
<!--rehype:wrap-class=row-span-2-->





















































































<table><thead><tr><th align="left">:-</th><th align="left">:-</th></tr></thead><tbody><tr><td align="left"><code>docker builder</code></td><td align="left">管理构建</td></tr><tr><td align="left"><code>docker buildx*</code></td><td align="left">Docker Buildx（Docker Inc.，v0.7.1）</td></tr><tr><td align="left"><code>docker compose*</code></td><td align="left">Docker Compose（Docker Inc.，v2.2.3）</td></tr><tr><td align="left"><code>docker config</code></td><td align="left">管理 Docker 配置</td></tr><tr><td align="left"><code>docker container</code></td><td align="left">管理容器</td></tr><tr><td align="left"><code>docker context</code></td><td align="left">管理上下文</td></tr><tr><td align="left"><code>docker image</code></td><td align="left">管理镜像</td></tr><tr><td align="left"><code>docker manifest</code></td><td align="left">管理 Docker 镜像清单和清单列表</td></tr><tr><td align="left"><code>docker network</code></td><td align="left">管理网络</td></tr><tr><td align="left"><code>docker node</code></td><td align="left">管理 Swarm 节点</td></tr><tr><td align="left"><code>docker plugin</code></td><td align="left">管理插件</td></tr><tr><td align="left"><code>docker scan*</code></td><td align="left">Docker 扫描（Docker Inc.，v0.16.0）</td></tr><tr><td align="left"><code>docker secret</code></td><td align="left">管理 Docker 机密</td></tr><tr><td align="left"><code>docker service</code></td><td align="left">管理服务</td></tr><tr><td align="left"><code>docker stack</code></td><td align="left">管理 Docker 堆栈</td></tr><tr><td align="left"><code>docker swarm</code></td><td align="left">管理群</td></tr><tr><td align="left"><code>docker system</code></td><td align="left">管理 Docker</td></tr><tr><td align="left"><code>docker trust</code></td><td align="left">管理对 Docker 映像的信任</td></tr><tr><td align="left"><code>docker volume</code></td><td align="left">管理卷</td></tr></tbody></table>
</div></div></div><div class="wrap h3body-not-exist"><div class="wrap-header h3wrap"><h3 id="docker-images"><a aria-hidden="true" tabindex="-1" href="#docker-images"><span class="icon icon-link"></span></a>docker images</h3><div class="wrap-body">
<pre class="language-bash"><code class="language-bash code-highlight"><span class="code-line">-a, <span class="token parameter variable">--all</span>             显示所有镜像（默认隐藏中间镜像）
</span><span class="code-line">    <span class="token parameter variable">--digests</span>         显示摘要
</span><span class="code-line">-f, <span class="token parameter variable">--filter</span> filter   根据提供的条件过滤输出
</span><span class="code-line">    <span class="token parameter variable">--format</span> string   使用 Go 模板打印漂亮的镜像
</span><span class="code-line">    --no-trunc        不要截断输出
</span><span class="code-line">-q, <span class="token parameter variable">--quiet</span>           仅显示镜像 ID
</span></code></pre>
</div></div></div></div></div><div class="wrap h2body-exist"><div class="wrap-header h2wrap"><h2 id="docker-示例"><a aria-hidden="true" tabindex="-1" href="#docker-示例"><span class="icon icon-link"></span></a>Docker 示例</h2><div class="wrap-body">
<!--rehype:body-class=cols-2-->
</div></div><div class="h2wrap-body cols-2"><div class="wrap h3body-not-exist"><div class="wrap-header h3wrap"><h3 id="docker-web-管理工具-portainer"><a aria-hidden="true" tabindex="-1" href="#docker-web-管理工具-portainer"><span class="icon icon-link"></span></a>Docker Web 管理工具 portainer</h3><div class="wrap-body">
<pre class="language-bash"><code class="language-bash code-highlight"><span class="code-line">$ <span class="token function">docker</span> run <span class="token parameter variable">-d</span> <span class="token parameter variable">--name</span> portainer <span class="token punctuation">\</span>
</span><span class="code-line">  <span class="token parameter variable">-p</span> <span class="token number">8000</span>:8000 <span class="token punctuation">\</span>
</span><span class="code-line">  <span class="token parameter variable">-p</span> <span class="token number">9443</span>:9443 <span class="token punctuation">\</span>
</span><span class="code-line">  <span class="token parameter variable">--restart</span><span class="token operator">=</span>always <span class="token punctuation">\</span>
</span><span class="code-line">  <span class="token parameter variable">-v</span> /var/run/docker.sock:/var/run/docker.sock <span class="token punctuation">\</span>
</span><span class="code-line">  <span class="token parameter variable">-v</span> <span class="token environment constant">$HOME</span>/portainer:/data <span class="token punctuation">\</span>
</span><span class="code-line">    portainer/portainer-ee:latest
</span></code></pre>
</div></div></div><div class="wrap h3body-not-exist"><div class="wrap-header h3wrap"><h3 id="在线代码编辑器-code-server"><a aria-hidden="true" tabindex="-1" href="#在线代码编辑器-code-server"><span class="icon icon-link"></span></a>在线代码编辑器 Code Server</h3><div class="wrap-body">
<pre class="language-bash"><code class="language-bash code-highlight"><span class="code-line">$ <span class="token function">mkdir</span> <span class="token parameter variable">-p</span> ~/.config
</span><span class="code-line">$ <span class="token function">docker</span> run <span class="token parameter variable">-it</span> <span class="token parameter variable">--name</span> code-server  <span class="token punctuation">\</span>
</span><span class="code-line">  <span class="token parameter variable">-p</span> <span class="token number">127.0</span>.0.1:8080:8080 <span class="token punctuation">\</span>
</span><span class="code-line">  <span class="token parameter variable">-v</span> <span class="token string">"<span class="token environment constant">$HOME</span>/.config/code-server:/home/coder/.config"</span> <span class="token punctuation">\</span>
</span><span class="code-line">  <span class="token parameter variable">-v</span> <span class="token string">"<span class="token environment constant">$PWD</span>:/home/coder/project"</span> <span class="token punctuation">\</span>
</span><span class="code-line">  <span class="token parameter variable">-u</span> <span class="token string">"<span class="token variable"><span class="token variable">$(</span><span class="token function">id</span> <span class="token parameter variable">-u</span><span class="token variable">)</span></span>:<span class="token variable"><span class="token variable">$(</span><span class="token function">id</span> <span class="token parameter variable">-g</span><span class="token variable">)</span></span>"</span> <span class="token punctuation">\</span>
</span><span class="code-line">  <span class="token parameter variable">-e</span> <span class="token string">"DOCKER_USER=<span class="token environment constant">$USER</span>"</span> <span class="token punctuation">\</span>
</span><span class="code-line">    codercom/code-server:latest
</span></code></pre>
</div></div></div><div class="wrap h3body-not-exist"><div class="wrap-header h3wrap"><h3 id="mysql"><a aria-hidden="true" tabindex="-1" href="#mysql"><span class="icon icon-link"></span></a>MySQL</h3><div class="wrap-body">
<pre class="language-bash"><code class="language-bash code-highlight"><span class="code-line">$ <span class="token function">docker</span> run <span class="token parameter variable">--name</span> mysql <span class="token punctuation">\</span>
</span><span class="code-line">  <span class="token parameter variable">-p</span> <span class="token number">3306</span>:3306 <span class="token punctuation">\</span>
</span><span class="code-line">  <span class="token parameter variable">-v</span> <span class="token environment constant">$HOME</span>/mysql/conf.d:/etc/mysql/conf.d <span class="token punctuation">\</span>
</span><span class="code-line">  <span class="token parameter variable">-v</span> <span class="token environment constant">$HOME</span>/mysql/data:/var/lib/mysql <span class="token punctuation">\</span>
</span><span class="code-line">  <span class="token parameter variable">-v</span> /etc/localtime:/etc/localtime:ro <span class="token punctuation">\</span>
</span><span class="code-line">  <span class="token parameter variable">-e</span> <span class="token assign-left variable">MYSQL_ROOT_PASSWORD</span><span class="token operator">=</span><span class="token number">123456</span> <span class="token punctuation">\</span>
</span><span class="code-line">  <span class="token parameter variable">-d</span> mysql:5.7.23
</span></code></pre>
</div></div></div><div class="wrap h3body-not-exist"><div class="wrap-header h3wrap"><h3 id="redis"><a aria-hidden="true" tabindex="-1" href="#redis"><span class="icon icon-link"></span></a>Redis</h3><div class="wrap-body">
<pre class="language-bash"><code class="language-bash code-highlight"><span class="code-line">$ <span class="token function">docker</span> run <span class="token parameter variable">-d</span> <span class="token parameter variable">--name</span> myredis <span class="token punctuation">\</span>
</span><span class="code-line">  <span class="token parameter variable">-v</span> <span class="token environment constant">$HOME</span>/redis/conf:/usr/local/etc/redis <span class="token punctuation">\</span>
</span><span class="code-line">  <span class="token parameter variable">-v</span> /etc/localtime:/etc/localtime:ro <span class="token punctuation">\</span>
</span><span class="code-line">    redis redis-server /usr/local/etc/redis/redis.conf
</span></code></pre>
</div></div></div><div class="wrap h3body-not-exist"><div class="wrap-header h3wrap"><h3 id="nginx"><a aria-hidden="true" tabindex="-1" href="#nginx"><span class="icon icon-link"></span></a>Nginx</h3><div class="wrap-body">
<pre class="language-bash"><code class="language-bash code-highlight"><span class="code-line">$ <span class="token function">docker</span> run <span class="token parameter variable">--name</span> my-nginx <span class="token punctuation">\</span> 
</span><span class="code-line">  <span class="token parameter variable">-v</span> <span class="token string">"<span class="token environment constant">$HOME</span>/nginx/nginx.conf:/etc/nginx/nginx.conf:ro"</span> <span class="token punctuation">\</span>
</span><span class="code-line">  <span class="token parameter variable">-v</span> <span class="token string">"<span class="token environment constant">$HOME</span>/nginx/html:/usr/share/nginx/html:ro"</span> <span class="token punctuation">\</span>
</span><span class="code-line">  <span class="token parameter variable">-p</span> <span class="token number">8080</span>:80 <span class="token punctuation">\</span>
</span><span class="code-line">  <span class="token parameter variable">-d</span> nginx
</span></code></pre>
</div></div></div><div class="wrap h3body-not-exist"><div class="wrap-header h3wrap"><h3 id="postgresql"><a aria-hidden="true" tabindex="-1" href="#postgresql"><span class="icon icon-link"></span></a>PostgreSQL</h3><div class="wrap-body">
<pre class="language-bash"><code class="language-bash code-highlight"><span class="code-line">$ <span class="token function">docker</span> run <span class="token parameter variable">--name</span> my-postgres <span class="token punctuation">\</span>
</span><span class="code-line">  <span class="token parameter variable">-e</span> <span class="token assign-left variable">POSTGRES_PASSWORD</span><span class="token operator">=</span>mysecretpassword <span class="token punctuation">\</span>
</span><span class="code-line">  <span class="token parameter variable">-e</span> <span class="token assign-left variable">PGDATA</span><span class="token operator">=</span>/var/lib/postgresql/data/pgdata <span class="token punctuation">\</span>
</span><span class="code-line">  <span class="token parameter variable">-v</span> <span class="token environment constant">$HOME</span>/nginx/mount:/var/lib/postgresql/data <span class="token punctuation">\</span>
</span><span class="code-line">  <span class="token parameter variable">-d</span> postgres
</span></code></pre>
</div></div></div><div class="wrap h3body-not-exist"><div class="wrap-header h3wrap"><h3 id="媒体管理工具-dim"><a aria-hidden="true" tabindex="-1" href="#媒体管理工具-dim"><span class="icon icon-link"></span></a>媒体管理工具 Dim</h3><div class="wrap-body">
<pre class="language-bash"><code class="language-bash code-highlight"><span class="code-line">$ <span class="token function">docker</span> run <span class="token parameter variable">--name</span> my-dim <span class="token punctuation">\</span>
</span><span class="code-line">   <span class="token parameter variable">-p</span> <span class="token number">8000</span>:8000/tcp <span class="token punctuation">\</span>
</span><span class="code-line">   <span class="token parameter variable">-v</span> <span class="token environment constant">$HOME</span>/.config/dim:/opt/dim/config <span class="token punctuation">\</span>
</span><span class="code-line">   <span class="token parameter variable">-v</span> <span class="token environment constant">$HOME</span>/dim/media:/media:ro <span class="token punctuation">\</span>
</span><span class="code-line">   <span class="token parameter variable">-d</span> ghcr.io/dusk-labs/dim:dev
</span></code></pre>
<p><a href="https://github.com/Dusk-Labs/dim">Github</a></p>
</div></div></div><div class="wrap h3body-not-exist"><div class="wrap-header h3wrap"><h3 id="gitlab"><a aria-hidden="true" tabindex="-1" href="#gitlab"><span class="icon icon-link"></span></a>Gitlab</h3><div class="wrap-body">
<pre class="language-bash"><code class="language-bash code-highlight"><span class="code-line">$ <span class="token function">docker</span> run <span class="token parameter variable">-d</span> <span class="token parameter variable">--name</span> gitlab <span class="token punctuation">\</span>
</span><span class="code-line">  <span class="token parameter variable">--hostname</span> gitlab.example.com <span class="token punctuation">\</span>
</span><span class="code-line">  <span class="token parameter variable">--publish</span> <span class="token number">8443</span>:443 <span class="token parameter variable">--publish</span> <span class="token number">8081</span>:80 <span class="token parameter variable">-p</span> <span class="token number">2222</span>:22 <span class="token punctuation">\</span>
</span><span class="code-line">  <span class="token parameter variable">--restart</span> always <span class="token punctuation">\</span>
</span><span class="code-line">  <span class="token parameter variable">--volume</span> <span class="token environment constant">$HOME</span>/gitlab/config:/etc/gitlab <span class="token punctuation">\</span>
</span><span class="code-line">  <span class="token parameter variable">--volume</span> <span class="token environment constant">$HOME</span>/gitlab/logs:/var/log/gitlab <span class="token punctuation">\</span>
</span><span class="code-line">  <span class="token parameter variable">--volume</span> <span class="token environment constant">$HOME</span>/gitlab/data:/var/opt/gitlab <span class="token punctuation">\</span>
</span><span class="code-line">  <span class="token parameter variable">-v</span> /etc/localtime:/etc/localtime <span class="token punctuation">\</span>
</span><span class="code-line">  --shm-size 256m <span class="token punctuation">\</span>
</span><span class="code-line">    gitlab/gitlab-ce:latest
</span></code></pre>
</div></div></div></div></div><div class="wrap h2body-not-exist"><div class="wrap-header h2wrap"><h2 id="另见"><a aria-hidden="true" tabindex="-1" href="#另见"><span class="icon icon-link"></span></a>另见</h2><div class="wrap-body">
<ul>
<li><a href="./dockerfile.html">Dockerfile 备忘清单</a> <em>(github.io)</em></li>
<li><a href="https://docs.docker.com/get-started/">Docker 官方入门教程</a> <em>(docker.com)</em></li>
<li><a href="https://jaywcjlove.github.io/docker-tutorial">Docker入门学习笔记</a> <em>(github.io)</em></li>
</ul>
</div></div><div class="h2wrap-body"></div></div></div><script src="https://giscus.app/client.js" data-repo="jaywcjlove/reference" data-repo-id="R_kgDOID2-Mw" data-category="Q&#x26;A" data-category-id="DIC_kwDOID2-M84CS5wo" data-mapping="pathname" data-strict="0" data-reactions-enabled="1" data-emit-metadata="0" data-input-position="bottom" data-theme="dark" data-lang="zh-CN" crossorigin="anonymous" async></script><div class="giscus"></div></div><footer class="footer-wrap"><footer class="max-container">© 2022 Kenny Wang.</footer></footer><script src="../data.js?v=1.5.2" defer></script><script src="../js/fuse.min.js?v=1.5.2" defer></script><script src="../js/main.js?v=1.5.2" defer></script><div id="mysearch"><div class="mysearch-box"><div class="mysearch-input"><div><svg xmlns="http://www.w3.org/2000/svg" height="1em" width="1em" viewBox="0 0 18 18">
  <path fill="currentColor" d="M17.71,16.29 L14.31,12.9 C15.4069846,11.5024547 16.0022094,9.77665502 16,8 C16,3.581722 12.418278,0 8,0 C3.581722,0 0,3.581722 0,8 C0,12.418278 3.581722,16 8,16 C9.77665502,16.0022094 11.5024547,15.4069846 12.9,14.31 L16.29,17.71 C16.4777666,17.8993127 16.7333625,18.0057983 17,18.0057983 C17.2666375,18.0057983 17.5222334,17.8993127 17.71,17.71 C17.8993127,17.5222334 18.0057983,17.2666375 18.0057983,17 C18.0057983,16.7333625 17.8993127,16.4777666 17.71,16.29 Z M2,8 C2,4.6862915 4.6862915,2 8,2 C11.3137085,2 14,4.6862915 14,8 C14,11.3137085 11.3137085,14 8,14 C4.6862915,14 2,11.3137085 2,8 Z"></path>
</svg><input id="mysearch-input" type="search" placeholder="搜索" autocomplete="off"><div class="mysearch-clear"></div></div><button id="mysearch-close" type="button">搜索</button></div><div class="mysearch-result"><div id="mysearch-menu"></div><div id="mysearch-content"></div></div></div></div></body>
</html>
